<?php
function lilina_user_search( $args ) 
{
    if(!xarVarFetch('startnum', 'isset', $startnum,  NULL, XARVAR_DONT_SET)) {return;}
    if(!xarVarFetch('header',   'isset', $header,    NULL, XARVAR_DONT_SET)) {return;}
    if(!xarVarFetch('q',        'isset', $q,         NULL, XARVAR_DONT_SET)) {return;}
    if(!xarVarFetch('bool',     'isset', $bool,      NULL, XARVAR_DONT_SET)) {return;}
    if(!xarVarFetch('sort',     'isset', $sort,      NULL, XARVAR_DONT_SET)) {return;}
    if(!xarVarFetch('author',   'isset', $author,    NULL, XARVAR_DONT_SET)) {return;}

    $q = "%$q%";

    $links = xarModAPIFunc('lilina',
                           'user',
                           'search',
                            array('q' => $q));
/*
    $data['pager'] = xarTplGetPager($startnum,
                                    xarModAPIFunc('lilina', 'user', 'countitems'),
                                    xarModURL('lilina', 'user', 'main', array('startnum' => '%%',
                                                                              'catid'    => $data['catid'],
                                                                              'hours'    => $hours)),
                                    xarModGetVar('lilina', 'itemsperpage'));
*/
    for ($i = 0; $i < count($links); $i++) {
        $link = $links[$i];


        $links[$i]['link'] = str_replace('&', '&amp;', $link['link']);
        $links[$i]['summary'] = xarModAPIFunc('lilina',
                              'user',
                              'garbage',
                              array('str' => $link['summary']));
        if (xarSecurityCheck('AdminLilina',0)) {
            $links[$i]['deleteurl'] = xarModURL('lilina',
                                                'admin',
                                                'add_garbage',
                                                array('id'      => $link['id'],
                                                      'unique'  => $link['unique']));
            $links[$i]['javascript'] = "return confirmLink(this, '" . xarML('Add to filtered content') . " $link[title] ?')";
        } 
         $text = $link['summary'];
         $text = preg_replace('/</',' <',$text);
         $text = preg_replace('/>/','> ',$text);
         $desc = html_entity_decode(strip_tags($text));
         $desc = preg_replace('/[\n\r\t]/',' ',$desc);
         $desc = preg_replace('/  /',' ',$desc);
        $links[$i]['summary'] = $desc;

         $text = $link['title'];
         $text = preg_replace('/</',' <',$text);
         $text = preg_replace('/>/','> ',$text);
         $desc = html_entity_decode(strip_tags($text));
         $desc = preg_replace('/[\n\r\t]/',' ',$desc);
         $desc = preg_replace('/  /',' ',$desc);
        $links[$i]['title'] = $desc;
    }
    $data['items'] = $links;
    return $data;
}
?>